package com.qf.mywatch.view;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.Toast;

import com.google.gson.Gson;

import com.qf.mywatch.R;
import com.qianfeng.utils.BitMapAsyncTask;
import com.qianfeng.utils.JSONAsyncTask;

import java.util.ArrayList;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

//广告页
public class AdvertisementActivity extends AppCompatActivity {

    private ImageView iv;
    private Timer timer;
    private Handler handler;
//    private ArrayList<AdvData> list;
    private Random rm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_advertisement);
        rm = new Random();
//        Log.e("aa", "onCreate: "+list.size() );
        iv = (ImageView) findViewById(R.id.iv_adver2);
//        new JSONAsyncTask(this, new JSONAsyncTask.CallBack() {
//            @Override
//            public void sendStr(String s) {
//                Adv adv = new Gson().fromJson(s, Adv.class);
//                list = new ArrayList<>();
//                list.addAll(adv.data);
//                int i = rm.nextInt(list.size());
//                new BitMapAsyncTask(AdvertisementActivity.this, new BitMapAsyncTask.CallBack() {
//                    @Override
//                    public void senBit(Bitmap bitmap, String s) {
//                        iv.setImageBitmap(bitmap);
//                    }
//                }).execute(list.get(i).cover);
//                handler = new Handler(new Handler.Callback() {
//                    @Override
//                    public boolean handleMessage(Message msg) {
//                        startActivity(new Intent(AdvertisementActivity.this,ZhuActivity.class));
//                        finish();
//                        return true;
//                    }
//                });
//                timer = new Timer();
//                //参数说明：1、子线程，2、延迟时间，3、间隔时间
//                timer.schedule(new TimerTask() {
//                    @Override
//                    public void run() {
//                        handler.sendEmptyMessage(10);
//                    }
//                }, list.get(i).loadingShowTime);
//            }
//        }).execute(Urls.ADV_PATH);//广告接口
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        timer.cancel();//取消定时器
    }

    public void click(View view) {
        Toast.makeText(this, "跳转广告连接", Toast.LENGTH_SHORT).show();
    }
}
